package com.datastructure.test.maxjumpgrade;

import java.util.Arrays;

public class MaxJumpGrade {

    public static void main(String[] args) {

    }

    public int maxJumpGrade (int[] nums) {
        // write code here
        int n = nums.length;
        if(n == 0) return -1;
        int[] dp = new int[n];
        Arrays.fill(dp, -1);
        dp[n - 1] = nums[n - 1];
        for(int cur = n - 2; cur >= 0; cur--){
            if(nums[cur] == 0) continue;
            for(int i = 1; i <= nums[cur]; i++){
                if(dp[Math.min(n - 1, cur + i)] != -1){
                    dp[cur] = Math.max(dp[cur], nums[cur] + dp[Math.min(n - 1, cur + i)]);
                }
            }
        }
        return dp[0];
    }
}
